<?php
class Game extends CI_Model {
	
    public function __construct(){
        $this->load->database();
        $this->load->library('factory');
        $this->factory->create('GameTO');
    }

    public function getAllGames(){        
        $sql = "SELECT * FROM game";
        $query = $this->db->query($sql);
        $games = array();
        foreach ($query->result() as $row){
            $gameTO = new GameTO();
            $gameTO->setId($row->id);
            $gameTO->setLeague($row->league);
            $gameTO->setHomeTeam($row->homeTeam);
            $gameTO->setAwayTeam($row->awayTeam);
            $gameTO->setPercentFix1($row->percentFix1);
            $gameTO->setPercentFixX($row->percentFixX);
            $gameTO->setPercentFix2($row->percentFix2);
            $gameTO->setTip($row->tip);
            $gameTO->setOdds1($row->odds1);
            $gameTO->setOddsX($row->oddsX);
            $gameTO->setOdds2($row->odds2);
            $gameTO->setScore1($row->score1);
            $gameTO->setScore2($row->score2);
            $gameTO->setUnder($row->under);
            $gameTO->setOver($row->over);
            $gameTO->setResult($row->result);
            $gameTO->setDateFromPage($row->dateFromPage);
            $gameTO->setRowNo($row->rowNo);
            $gameTO->setTimestamp($row->timestamp);
            array_push($games, $gameTO);
        }
        return $games;
    }
    
    public function insertGame($game){  
    	//echo '<pre>';  	
    	$sql = "INSERT INTO game VALUES ('','".$game->getLeague()."','".$game->getHomeTeam()."','".$game->getAwayTeam()."','".$game->getPercentFix1()."','".$game->getPercentFixX()."','".$game->getPercentFix2()."','".$game->getTip()."','".$game->getOdds1()."','".$game->getOddsX()."','".$game->getOdds2()."','".$game->getScore1()."','".$game->getScore2()."','".$game->getUnder()."','".$game->getOver()."','".$game->getResult()."','".$game->getDateFromPage()."','".$game->getRowNo()."','".$game->getTimestamp()."')";
    	//echo $sql;
    	//echo '</pre>';
    	$query = $this->db->query($sql);
    	//INSERT INTO table_name
    	//VALUES (value1, value2, value3,...)
    	
    }
    
    public function updateGame($gameDb,$gameCron){
    	$sql = "UPDATE game SET odds1='".$gameCron->getOdds1()."' ,oddsX='".$gameCron->getOddsX()."' ,odds2='".$gameCron->getOdds2()."' ,result='".$gameCron->getResult()."' WHERE id='".$gameDb->getId()."'";
    	$query = $this->db->query($sql);
    	//echo $sql;    	
    }
    
    
}
?>